package action.iterator;

import java.util.List;

public class ConcreteIterator<T> implements Iterator {
    //迭代器对象持有聚合类对象引用
    private List<T> list;
    //游标
    private int cur;

    public ConcreteIterator(List<T> list) {
        this.list = list;
        cur=0;
    }


    @Override
    public boolean hasNext() {
        return cur < list.size();
    }

    @Override
    public T next() {
        return list.get(cur++);
    }
    //这里未定义从后遍历的方式，可以通过在构造函数中加入标志位实现遍历方式的多样化
    @Override
    public boolean hasPrevious() {
        return false;
    }

    @Override
    public Object previous() {
        return null;
    }


}
